<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller 
{
  	public function index()
		{
			if(!isset($_SESSION['userid']))
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
				}
			//echo 	$_SERVER['REMOTE_ADDR'];die;
			$t_login_record=M('t_login_record');											//登录记录表		
			$sql=$t_login_record->where('accounts='.$_SESSION['accounts'])->find();			//登录用户的信息
		
			//得到  当前数据库时间戳大于当前时间戳的数据
			$this->assign('User_Profile',$User_Profile);									//传递数组
			$this->assign('sql',$sql);
			$this->display();
		}

		 /* 在线用户页面 没有状态显示，所以无法读出 */ 
	public function sinfo()
	{
		
		$this->display();	
	}
	/*      修改密码           */
	public function modipass()
	{
			if(!isset($_SESSION['userid']))
			{
				echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
				echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";die;
			}
			$t_agent= M('','t_agent','DB_CONFIG0'); 
			if(IS_POST)
			{
				if($_POST['password']=="" || $_POST['passwordd']==""){
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('密码不能为空');history.go(-1)</script>";
				}
				if($_POST['password']!=$_POST['passwordd'])
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('您输入的新密码和确认密码不一致，请重新输入');history.go(-1)</script>";die;
				}
				if(strlen($_POST['password'])<6)
				{
					echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
					echo "<script type='text/javascript'>alert('请按照规范更改密码');history.go(-1)</script>";die;
				}
				if(MD5($_POST['password'])==MD5($_POST['passwordd']))
				{
					$t_agent->password=MD5($_POST['password']);
					$new_password=$t_agent->where('userid='.$_SESSION['userid'])->save();
					if($new_password)
					{
						$state=0;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','更改用户密码','$state')");
					}else
					{
						$state=1;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','更改用户密码','$state')");
					}
					if($new_password)
					{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('密码重置成功，请保管好您的密码。');location.href='".U('Login/login')."'</script>";
					}
					else
					{
						echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
						echo "<script type='text/javascript'>alert('系统繁忙，请您重再次输入');history.go(-1)</script>";
					}
				}
			}
		$this->display();
	}
	
	/*  当天活跃玩家       */
	public function active_player()
	{
		if(!isset($_SESSION['userid']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$deputy=M("","t_user_everyday_record","DB_CONFIG1")->select();
		if(IS_POST)
		{
			if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['userid']=array('like','%'.$_POST['userid'].'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$_POST['name'].'%');//把数据写到空数组去  
				$deputy=M("","t_user_everyday_record","DB_CONFIG1")->where($w)->select();
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}	
			if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=$_POST['sdate']; //POST来的时间转为时间戳
				$edate=$_POST['edate'];	//POST来的时间转为时间戳
				$arr['record_time']=array('between',array($sdate,$edate));
				$deputy=M("","t_user_everyday_record","DB_CONFIG1")->where($arr)->select();//时间不符合    需要修正！！！！
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
		}
		$this->assign('deputy',$deputy);
		$this->display();
	}	
	//当天代理信息
	public function active_agent()
	{
		if(!isset($_SESSION['userid']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$deputy=M("","t_agent_total_record","DB_CONFIG1")->select();
		if(IS_POST)
		{
			if($_POST['accounts']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['accounts']=array('like','%'.$_POST['accounts'].'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$_POST['name'].'%');//把数据写到空数组去  
				$deputy=M("","t_agent_total_record","DB_CONFIG1")->where($w)->select();
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}	
			if($_POST['accounts']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=$_POST['sdate']; //POST来的时间转为时间戳
				$edate=$_POST['edate'];	//POST来的时间转为时间戳
				$arr['record_time']=array('between',array($sdate,$edate));
				$deputy=M("","t_agent_total_record","DB_CONFIG1")->where($arr)->select();//时间不符合    需要修正！！！！
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
		}
		$this->assign('deputy',$deputy);
		$this->display();
	}
	//当天总信息
	public function day_information()
	{
		if(!isset($_SESSION['userid']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$deputy=M("","t_everyday_total_record","DB_CONFIG1")->select();
		if(IS_POST)
		{
			if($_POST['newusernum']!="" || $_POST['usernum']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['newusernum']=array('like','%'.$_POST['newusernum'].'%');//把数据写到空数组去  
				$w['usernum']=array('like','%'.$_POST['usernum'].'%');//把数据写到空数组去  
				$deputy=M("","t_everyday_total_record","DB_CONFIG1")->where($w)->select();
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}	
			if($_POST['newusernum']=="" AND $_POST['usernum']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=$_POST['sdate']; //POST来的时间转为时间戳
				$edate=$_POST['edate'];	//POST来的时间转为时间戳
				$arr['record_time']=array('between',array($sdate,$edate));
				$deputy=M("","t_everyday_total_record","DB_CONFIG1")->select();//时间不符合    需要修正！！！！
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
		}
		$this->assign('deputy',$deputy);
		$this->display();
	}
				/* 代理商用户信息 */
		public function journal()
	{				
		if(!isset($_SESSION['userid']))
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
			echo "<script type='text/javascript'>alert('请登录');location.href='".U('Login/login')."'</script>";
		}
		$sql=M("","","DB_CONFIG0")->query('select * from t_journal');
		if(IS_POST)
		{
			if($_POST['userid']!="" || $_POST['name']!="" AND $_POST['sdate']=="" AND $_POST['edate']=="" )
			{
				$w['action']=array('like','%'.$_POST['name'].'%');												//把数据写到空数组去  
				$w['accounts']=array('like','%'.$_POST['userid'].'%');												//把数据写到空数组去  
				$sql=M('t_journal')->where($w)->select();														//echo M('t_agent_add_cards_to_agent')->_sql();die;
				if($sql)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}
			}	
			if($_POST['userid']=="" AND $_POST['name']=="" AND $_POST['sdate']!="" || $_POST['edate']!="")
			{
				$sdate=$_POST['sdate'];																		//POST来的时间转为时间戳
				$edate=$_POST['edate'];																		//POST来的时间转为时间戳
				$arr['times']=array('between',array($sdate,$edate));															//判断大于等于起始时间的条件
				$sql=M('t_journal')->where($arr)->select();  //时间不符合    需要修正！！！！				
				if($sql)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}				
			}
		}
		$this->assign('sql',$sql);
		$this->display();
	}
}





































































